%% file: TXSpatch.tex                                    TeXsis 2.15/m
%  $Revision: 16.12 $  :  $Date: 93/12/03 10:32:55 $  :  $Author: myers $
%======================================================================*
% The file TXSpatch.tex is read in by texsis at run time, if it
% exists.  These patches correct minor problems which will be fixed
% in the next release of TeXsis.  

%%\def\revdate{13 August 1992}\def\fmtversion{2.15/c}%
%%\def\revdate{29 September 1992}\def\fmtversion{2.15/d}%
%%\def\revdate{10 October 1992}\def\fmtversion{2.15/e}%
%%\def\revdate{12 October 1992}\def\fmtversion{2.15/f}%
%%\def\revdate{20 November 1992}\def\fmtversion{2.15/g}%
%%\def\revdate{1 March 1993}\def\fmtversion{2.15/h}%
%%\def\revdate{5 May 1993}\def\fmtversion{2.15/i}%
%%\def\revdate{16 October 1993}\def\fmtversion{2.15/j}%
%%\def\revdate{19 November 1993}\def\fmtversion{2.15/k}%
\def\revdate{3 December 1993}\def\fmtversion{2.15/m}%

\ATunlock       % make @ a letter for "hidden" macro names

%==================================================*
% Patch a:  Reference citations and numbering
%
% In citations to equation numbers which have letters in them the
% letters should be in (math) italics, just as in the original equation
% number.  Thus the citation macros should put \use in math quotes.  

\def\Eq#1{Eq.~($\use{Eq.#1}$)}          % \Eq  prints  "Eq. (nn)"
\def\Eqs#1{Eqs.~($\use{Eq.#1}$)}        % \Eqs prints  "Eqs. (nn)"
\def\Ep#1{($\use{Eq.#1}$)}              % \Ep  prints just "(nn)"


% Also, \frac got changed, so change it back to what it used to be

\def\frac#1#2{{#1\over #2}}


% Not a bug patch, but a nice improvement.  The following code
% causes \ListReferences to reset everything so that you can
% continue collecting references.  The counters are reset to zero
% and \refint is re-initialized so that it will re-open the .ref file.
% [Thanks to Betty A for suggesting this.  It will be a part of the
% next release.]

% \refReset resets the counters so that more references can be created
% after \ListReferences has been called.  For example, if you listed the
% references for one chapter and want to begin collecting references for
% the next chapter. 

\def\refReset{% reset reference/citation counters
   \global\refnum=\z@                           % counter for reference numbers
   \global\@firstrefnum=1                       % first of a series of refs
   \global\@lastrefnum=1                        % last of a series of refs
   \global\@BadRefs=0                           % count undefined references
   \gdef\refinit{\@refinit}%                    % re-enable \refinit
   }

% need to change \refinit so it can be turned on again later, if
% need be.

\def\@refinit{\ifrefswitch               % is .ref ouput enabled?
   \immediate\openout\reflistout=\jobname.ref  % y: open .ref file for output
  \else                                 % no:
    \let\@refwrite=\@refwrong           %   disable output
    \let\@refNXwrite=\@refwrong         %   disable output
    \immediate\closeout\reflistout      % and make sure output closed
  \fi                                   %
  \gdef\refinit{\relax}%                % disable \refinit once it's done
}%

\def\refinit{\@refinit}                 % start with \refinit enabled

%==================================================*
% Patch b:  fix \EQNdisplaylines
%
% previous version of \EQNdisplaylines did not work like \displaylines
% when it came to left justifying equations with \hfill. This one does.  

\def\EQNdisplaylines#1{%                % make \EQN re-\def local
   \@EQNcr                              % change \def of \EQN to get label
   \displ@y                             % reduce interline spacing (from Plain)
   \halign{%                            % alignment
      \hbox to\displaywidth{%           % full width
      $\@lign\hfil\displaystyle##\hfil$}% centered displaystyle
      &\llap{$\@lign\@@EQN{##}$}\crcr   % then eqn number template
   #1\crcr}%                            % now apply template to argument
   \@EQNuncr}                           % put \EQN back to normal


%==================================================*
% Patch c: fix the problem with \@eatpar eating \def's 
%
% \@eatpar gets rid of any \par that follows.  We have to use \futurelet
% to avoid problems when what follows is a \def or somesuch.
     
\def\@eatpar{\futurelet\next\@testpar}
\def\@testpar{\ifx\next\par\let\@next=\@@eatpar\else\let\@next=\relax\fi\@next}
\long\def\@@eatpar#1{\relax}

%==================================================*
% patch d:  \loadstyle fails on PC-TeX and NorthLake TeX, so..
%
% Previously \loadstyle used \openin to try to determine if the style
% file to load existed.  If it could not be opened then \ifeof would be
% true.  However, some implementations of TeX do not look through the
% whole TEXINPUTS path for \openin (as they do for \input) so this is
% not a reliable test.  We consider this a bug, but we have to live with
% it until those guys get their TeX fixed!  So now we just use \input to
% read the style file.  But if \openin can't find the file we at least
% say what we are trying to do, in case it does fail.  

\newread\txsfile                % to help look for style files

\def\loadstyle#1#2{%            % load a definition for #1 from file #2
   \def#1{\@loaderr{#1}}%       % disable #1 (just in case...)
   \ATunlock                    % make @ a letter, in case it's in the file
   \immediate\openin\txsfile=#2 % try to open the file to see if it exists
   \ifeof\txsfile               % if end of file, then print a message
      \emsg{> Trying to load the style file #2...}% before trying to \input
   \fi                          %
   \closein\txsfile             % just close the file in any case
   \input #2 \relax             % load (or try to) the file with the new \def
   \ATlock                      % @ now no longer a letter
   #1}                          % now use the new definitions


%==================================================*
% patch e: \@BadTags and \@BadRefs should use \global\advance
%
% in TXStags.tex:

\def\@use#1{%   does the work for \use
   \endgroup                                    % end unspecial characters
   \stripblanks @#1@\endlist                    % @name@ -> \tok w/o blanks
   \XA\ifx\csname\tok\endcsname\relax\relax     % is \@name@ undefined?
     \emsg{> UNDEFINED TAG #1 ON PAGE \folio.}% % yes: error message
     \global\advance\@BadTags by 1              % count how many
     \@errmark{UNDEF}%                          %   and mark in output
     \edef\tok{{\bf\tok}}%                      % and return \bf ``name''
   \else                                        % else:
     \edef\tok{\csname\tok\endcsname}%          %  get the definition
   \fi                                          %
   \tok}                                        % evaluate it


% in TXSrefs.tex:

\def\make@refmark#1{% make a reference mark
  \testtag{Ref.#1}\ifundefined           % is it undefined? (tag -> \tok)
    \emsg{> UNDEFINED REFERENCE #1 ON PAGE \number\pageno.}% error message
    \global\advance\@BadRefs by 1        % count undefined references
    \xdef\@refmark{{\tenbf #1}}%         % cite with label in boldface
    \@errmark{REF?}%                     % and mark error in output
  \else                                  % no:
    \xdef\@refmark{\csname\tok\endcsname}%  cite with number
  \fi}                                   % end of \ifundefined


%==================================================*
% patch f:  TXSfigs.tex
%
% \infiglist and \intablelist were getting page numbers wrong
% when many figures were inserted.  The problem was the page number
% (\folio) was being evaluated when the macro was called, not when the
% \write to the file was actually being performed.  Inserting one
% \noexpand solves the problem.


\def\@infiglist#1#2{% write to list of figures or tables
   \FigListWrite#1{\@comment}%                  % comment '%'
   \FigListWrite#1{\@comment \CaptionName\space\@ID:}% comment '%'
   \FigListWrite#1{\NX\NX\NX\FIGLitem{\CaptionName} {\@ID.\space}}% 
   \FigListWriteNX#1{{#2}}%      the caption text should not be expanded at all!
   \FigListWrite#1{{\NX\folio}}% the page number, so don't expand until written
   \endgroup}                                   % end \obeylines

%==================================================*
% patch g:  TXSrefs.tex (supersceded by patch j)
%
%==================================================*
% patch h:  TXSfmts.tex
%
% \Manuscript was just \preprint with true double spacing, but Phys.
% Rev. is now more specific about how submitted manuscripts should
% appear.  Further improvements or suggestions are welcome, and we'll
% keep working on this.

\def\Manuscript{% layout for manuscripts to be submitted to journals
   \preprint                    % start with preprint form
   \showsectIDfalse             % no section number in equation numbers
   \showchaptIDfalse            % no chapter number in equation numbers
   \def\SectionStyle##1{\uppercase       % section numbers in upper case
         \expandafter{\romannumeral ##1}}%     roman numerals
   \RomanTablestrue             % roman numerals for table numbers
   \TablesLast                  % tables at the end
   \FiguresLast                 % figures at the end
   \TrueDoubleSpacing           % wider interline spacing for manu
   }


%% TXSfigs.tex:  

%  \ListFigureCaptions uses a modified \FIGLitem and the figure list file
%  to list just the captions, but without the page numbers.  Use this
%  at the end of your document to get a list of all the captions.

\def\ListFigureCaptions{%  print figure captions only, no page numbers
   \showsectIDtrue                              % do print ``Figure''
   \emsg{\@comment List of Figure Captions:}%   % message
   \immediate\closeout\figlist                  % close caption list file
   \openin\figlist=\jobname.fgl                 % reopen to read it 
   \ifeof\figlist\closein\figlist               % if EOF just close it
      \emsg{> \NX\ListFigureCaptions: no list of figures.}%  and complain
   \else\closein\figlist                        % else close it and 
     \begingroup                                % read it in...
      \ATunlock\quoteoff\offparens              % \specials not active
      \let\FIGLitem=\CAPLitem                   % use modified \FIGLitem
      \Input\jobname.fgl \relax                 % read in captions
     \endgroup                                  %
   \fi}                                                  % else ignore it



% \CAPLitem is like \FIGLitem above, but it just ignores #4

\def\CAPLitem#1#2#3#4{% Figure or Table list item for list of captions
   \medskip                                     % some space between items
   \begingroup                                  %
     \raggedright\tolerance=1700                % don't justify
     \advance\rightskip by \TOCmargin           % right margin comes in, but
     \parfillskip=-\TOCmargin                   % page number at edge of page
     \hangindent=1.41\parindent\hangafter=1     % hanging indentation
     \noindent \ifshowsectID #1\ \fi #2         % show section numbers
        #3 \hskip 0pt plus 10pt                 % text of ``caption''
     \vskip 0pt                                 % end paragraph
   \endgroup}                                   %

%==================================================*
% patch i:
%
% TXSenvmt.tex:   \Listing was fixed in patch e so that ~ was not active.
% This fixes the spacing problems and adds \everyListing

\def\Listing{%  environment for listing computer code verbatim in \tt
   \beginEnv{Listing}%                          %
   \vskip\EnvDelt@skip                          % do extra skip
   \baselineskip=\normalbaselineskip            % singlespaced
   \parskip=\z@ \parindent=\z@                  % set \par indentation to zero
   \def\\##1{\char92##1}%                       % \ for macro names
   \catcode`\{=\other \catcode`\}=\other        % { and } just characters
   \catcode`\(=\other \catcode`\)=\other        % ( and ) just characters
   \catcode`\"=\other \catcode`\|=\other        % " and | just characters
   \catcode`\%=\other \catcode`\&=\other        % so %  and & are characters
   \catcode`\-=\other \catcode`\==\other        % so -  and = are characters
   \catcode`\$=\other \catcode`\#=\other        % so $  and # are characters
   \catcode`\_=\other \catcode`\^=\other        % so _  and ^ are characters
   \catcode`\~=\other \catcode`\ =\other        % ~ is not active tie!
   \obeylines                                   % obey line endings,
   \tt\Listingtabs                              % spaces and tabs   
   \everyListing}                               % user customization

%  Use \everyListing to customize your \Listing.  

\def\everyListing{}

% Use \ListCodeFile{<filename>} to directly include a source file
% in the document.  Use this INSTEAD of \Listing, not after it.
% Nothing in this file is ``active,'' so you cannot have TeX commands
% in the file.  Example:  \ListCodeFile{hello.c}

\def\ListCodeFile#1{%  print the named file verbatim using \Listing
   \Listing                             % invoke \Listing and read in file
   \hsize=2\hsize\raggedright           % allow overflow in right margin
   \catcode`\\=\other                   % \ is not active!
   \input #1\relax                      % read in source file
   \endListing}

{\catcode`\^^I=\active\catcode`\ =\active% no spaces in any of this!
\gdef\Listingtabs{\catcode`\^^I=\active\let^^I\@listingtab%
\catcode`\ =\active\let \@listingspace}%
}%\global\let^^I\@listingtab}%

\def\@listingspace{\hskip 0.5em}                % \tt space is 0.5em
 \def\@listingtab{\hskip 4em}                    % eight spaces per tab

% TXSdcol.tex:  a \pageinsert in double column mode should still give
% a full page insert, while \fullinsert does a full *column*.
% A more complete overhaul of inserts in double columns will appear
% in 2.16.

\def\@doublecolumns{%                           % begin 2 columns
   \begingroup                                  % keep changes local
   \def\endmode{\@enddoublecolumns}             % how to end 
   \output={\global\setbox\partialpage=%        % set up output
      \vbox{%                                   % box containing...
         \ifvoid\topins\else\unvbox\topins\fi%  %top insert
         \unvbox255}}\eject                     % and main page
   \output={\d@ublec@lumnout}%                  % set 2 column output
   \long\def\fullfigure{\@figure\fullpageinsert}% full figures on full page
   \s@vesize=\vsize                             % save old \vsize
   \hsize=\colwidth\vsize=\bigc@lheight         % set width, 2*height
   \advance \vsize by -2\ht\partialpage         %   less partial page
   \advance \vsize by -2\dp\partialpage         %   less partial page
   \global\s@veskip=\spaceskip                  % save old interword glue
   \global\spaceskip=\doublecolskip             % stretch for small cols.
   \global\displaywidth=\colwidth               % equations have \colwidth
   \global\hyphenpenalty=0                      % hyphens are OK
   \let\topinsert=\topinsertd@uble              % 2-col top insert
   \global\let\midinsert=\midinsertd@uble       %   mid insert
   \global\let\fullinsert=\pageinsertd@uble     %   full column insert
   \global\let\pageinsert=\fullpageinsert       %   full PAGE insert
   \global\let\endinsert=\endinsertd@uble       % 2-col end inserts
   \global\let\widetopinsert=\widet@pinsert     % allow wide inserts
   \global\let\widepageinsert=\widep@geinsert   % or full page inserts
   \global\let\newcolumn=\@newcolumn            % to break columns
}


%==================================================*
% patch j:  16 October 1993  -EAM
%
% TXSrefs.tex: problems with -- in \citemark, and with \refrange spacing

\def\citemark#1{% output the citation marks in the text
   \relax\let\@sf\empty                         %
   \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\/\fi % save spacefactor
   \ifsuperrefs                                 % superscript references?
      $\relax{}^{\hbox{$\citestyle               % small numbers
           #1\refterminator$}}$\relax            % superscript
   \else                                        %
      {}~[{#1}]\relax                           % [] style
   \fi                                          %
   \@sf}%                                       % restore spacefactor

% Use en dash in \refrange rather than hyphen. (Betty A and Tim Pearce)

\long\def\refrange#1#2#3{% cites a range of references
  \reffollowsfalse                      % assume no ref. follows
  \ifx#3\cite\reffollowstrue\fi         % is next token another \cite?
  \ifx#3\ref\reffollowstrue\fi          % (or \ref, OLD TeXsis)
  \ifx#3\reference\reffollowstrue\fi    % or is it \reference? then set flag.
  \ifx#3\refrange\reffollowstrue\fi     % or \refrange
% --- construct reference mark in \@refmark
  \make@refmark{#2}%                    % ref mark for 2nd ref
  \xdef\@refmarktwo{\@refmark}%         % save for later
  \make@refmark{#1}%                    % ref mark for 1st ref
  \xdef\@refmark{\@refmark\hbox{--}\@refmarktwo}% create range of references
%
  \add@refmark                          % add to \@refmarklist
  \flush@reflist{#3}%                   % flush output list
  #3}%                                  % do the remaining #3 args

\newlinechar=`\^^M                  % <CR> breaks lines in file output
\def\Afour{\hsize=16.5cm \vsize=24.5cm} % A4 paper size

%==================================================*
% patch k:  19 November 1993  -EAM
%
% TXSrefs.tex: problems with \endreference followed by punctuation

\long\def\@endreference#1{% end a \reference and look ahead at next token
  \reffollowsfalse                              % assume no cit'ns follow
  \ifx#1\cite\reffollowstrue\fi                 % is next token another \cite?
  \ifx#1\refrange\reffollowstrue\fi             % or \refrange
  \ifx#1\ref\reffollowstrue\fi                  % (or \ref, OLD TeXsis)
  \ifx#1\reference\reffollowstrue               % if \reference set flag
  \else                                         %     but nothing more
   \ifnum\@firstrefnum>\@lastrefnum\relax       % If *'d \reference, \relax
   \else\ifmarkit                               % so can we write citation?
% --- construct the reference mark for this reference or range in \@refmark
    \ifnum\@firstrefnum=\@lastrefnum            % is there only one reference?
      \xdef\@refmark{\the\@lastrefnum}%         % yes: write only one number
    \else                                       % no: write a 
      \xdef\@refmark{\the\@firstrefnum-\the\@lastrefnum}% range of numbers
    \fi                                         % end \ifnum
    \global\@firstrefnum=\refnum                % reset \@firstrefnum to be
    \global\advance\@firstrefnum by \@ne        %   \refnum + 1
%
    \add@refmark                        % add \@refmark to \@refmarklist
   \fi\fi                               % end \ifnum and \ifmarkit
  \fi                                   % end \ifx#1\reference
  \flush@reflist{#1}%                   % output ref mark list
  \def\@next{#1}\ifcat.\NX#1\def\@next{#1 }\fi % space after if punctuation
  \@next}                                  % do the remaining #1 lookahead

%==================================================*
% patch m:  3 December 1993  -EAM
%
% TXSfigs.tex: list of table captions was trying to read wrong file

%  \ListTableCaptions is just like \ListFigureCaptions but for the 
% list of table captions.

\def\ListTableCaptions{%  print table captions only, no page numbers
   \showsectIDtrue                              % do print ``Table''
   \emsg{\@comment List of Table Captions:}%    % message
   \immediate\closeout\figlist                  % close caption list file
   \openin\figlist=\jobname.tbl                 % reopen to read it 
   \ifeof\figlist\closein\figlist               % if EOF just close it
      \emsg{> \NX\ListFigureCaptions: no list of figures.}%  and complain
   \else\closein\figlist                        % else close it and 
     \begingroup                                % read it in...
      \ATunlock\quoteoff\offparens              % \specials not active
      \let\FIGLitem=\CAPLitem                   % use modified \FIGLitem
      \Input\jobname.tbl \relax                 % read in captions
     \endgroup                                  %
   \fi}                                                  % else ignore it

%======================================================================*
\ATlock         % make @ not a letter (hides internal macros).

\emsg{Patched to Version \fmtversion, \revdate.}%

%>>> EOF TXSpatch.tex
